package com.sample.test.service;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sample.test.model.Order;
import com.swak.annotation.Tcc;

@Service
public class OrderService {

	/**
	 * 开启分布式事务
	 */
	@Tcc(confirm = "bookConfirm", cancel = "bookCancel")
	@Transactional
	public void book() {
		Order.of().setOrderNo("1").setCommodityCode("001").setCount(1).setAmount(BigDecimal.valueOf(1)).insert();
		List<Order> orders = Order.of().andLike("orderNo", "1").query();
		System.out.println(orders); 
	}

	/**
	 * 执行确认回调
	 */
	@Transactional
	public void bookConfirm() {
		System.out.println("执行确认回调");
	}

	/**
	 * 执行取消回调
	 */
	@Transactional
	public void bookCancel() {

	}
}
